/*
题目描述
请实现一个函数，用来判断一颗二叉树是不是对称的。注意，如果一个二叉树同此二叉树的镜像是同样的，定义其为对称的。

思路：
（1）镜面，值相等


*/



class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}

public class Solution {
    boolean isSymmetrical(TreeNode pRoot)
    {
        TreeNode left,right;
        TreeNode inner = new TreeNode(0);
        TreeNode outer = new TreeNode(0);
        if(pRoot==null)
            return true;
        else{
            left = pRoot.left;
            right = pRoot.right;
            if (left == null && right == null)
                return true;
            else if((left == null|| right == null)){
                return false;
            }else if(left.val!= right.val){
                return false;
            }else{
                inner.left = left.right;
                inner.right = right.left;
                outer.left = left.left;
                outer.right = right.right;
                return isSymmetrical(inner) && isSymmetrical(outer);
            }
        }

    }
    public static void main(String args[]){
        Solution s = new Solution();
        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(2);
        TreeNode node4 = new TreeNode(1);
        TreeNode node5 = new TreeNode(3);
        TreeNode node6 = new TreeNode(3);
        TreeNode node7 = new TreeNode(4);

        node1.left = node2;
        node1.right = node3;
        node2.left = node4;
        node2.right = node5;
        node3.left = node6;
        node3.right = node7;
        Boolean a = s.isSymmetrical(node1);
        System.out.println("hah");

    }

}